package com.four.dailymanage.chamber.dao;


import com.four.dailymanage.chamber.entity.Chamber;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ChamberDao{

    /**
     * 分页的形式展示会议室基本信息
     * @param start 页数
     * @param size  每页记录数
     * @param cname 会议名
     * @param cno   会议编号
     * @return
     */
    @Select("<script>" +
            "SELECT * FROM chamber" +
            "  <where>" +
            "    <if test=\" cname != null\">" +
            "    <bind name=\"Key\" value=\"'%'+cname+'%'\"/>"+
            "       cname like #{Key} " +
            "    </if>" +
            "    <if test=\" cno != null\">" +
            "     <bind name=\"cnoKey\" value=\"'%'+cno+'%'\"/>"+
            "       and cno like #{cnoKey} " +
            "    </if>" +
            "    <if test=\" status != null\">" +
            "       and status = #{status} " +
            "    </if>" +
            "</where>"+
            "limit #{start},#{size}"+
            "</script>")

    public List<Chamber> getChamberByCon(int start,int size,String cname,String cno,String status);

    /**
     * 根据条件统计会议室有多少间
     * @param cname
     * @param cno
     * @return
     */
    @Select("<script>" +
            "select count(*) from chamber" +
            "  <where>" +
            "    <if test=\" cname != null\">" +
            "    <bind name=\"Key\" value=\"'%'+cname+'%'\"/>"+
            "       cname like #{Key} " +
            "    </if>" +
            "    <if test=\" cno != null\">" +
            "     <bind name=\"cnoKey\" value=\"'%'+cno+'%'\"/>"+
            "       and cno like #{cnoKey} " +
            "    </if>" +
            "    <if test=\" status != null\">" +
            "       and status = #{status} " +
            "    </if>" +
            "</where>"+
            "</script>")
    public  int countChamber(String cname,String cno,String status);
    //新增一间会议室
    @Insert("insert into chamber (cname,cno,caption,position,contain,note,status) values (#{cname},#{cno},#{caption},#{position},#{contain},#{note},#{status})")
    public  int insertChamber(Chamber chamber);
    //删除一间会议室
    @Delete("delete from chamber where id=#{id}")
    public int deleteChamber(Integer id);

    //更新会议室使用情况
    @Update("<script>" +
            "update  chamber " +
            "        <set>" +
            "            <if test=\"null!= caption\">" +
            "                caption =#{caption}," +
            "            </if>" +
            "            <if test=\"null!= note\">" +
            "                note =#{note}," +
            "            </if>" +
            "            <if test=\"null!= status\">" +
            "                status =#{status}," +
            "            </if>" +
            "        </set>" +
            "        where id =#{id}" +
            "</script>")
    public  int  updateChamber(Chamber chamber);
}
